package com.jeesite.modules.sys.utils;

import java.util.List;

import com.jeesite.common.cache.CacheUtils;
import com.jeesite.common.utils.SpringUtils;
import com.jeesite.modules.edu.entity.EduIndustry;
import com.jeesite.modules.edu.entity.EduProfessionalTitle;
import com.jeesite.modules.edu.entity.EduSubject;
import com.jeesite.modules.edu.entity.EduTalent;
import com.jeesite.modules.edu.entity.EduTeacherTitle;
import com.jeesite.modules.edu.entity.EduTwoOrganization;
import com.jeesite.modules.edu.service.EduIndustryService;
import com.jeesite.modules.edu.service.EduProfessionalTitleService;
import com.jeesite.modules.edu.service.EduSubjectService;
import com.jeesite.modules.edu.service.EduTalentService;
import com.jeesite.modules.edu.service.EduTeacherTitleService;
import com.jeesite.modules.edu.service.EduTwoOrganizationService;

public class EduUtils {
	// 系统缓存常量
		public static final String CACHE_TEACHER_ALL_LIST = "teacherAllList";
		public static final String CACHE_PROFESSIONAL_ALL_LIST = "professionalAllList";
		public static final String CACHE_EDU_TWO_ORGANIZATION_ALL_LIST = "organizationAllList";
		public static final String CACHE_EDU_SUBJECT_ALL_LIST = "subjectAllList";
		public static final String CACHE_EDU_TALENT_ALL_LIST = "talentAllList";
		public static final String CACHE_EDU_INDUSTRY_ALL_LIST = "industryAllList";
		/**
		 * 静态内部类，延迟加载，懒汉式，线程安全的单例模式
		 */
		private static final class Static {
			private static EduTeacherTitleService eduTeacherTitleService = SpringUtils.getBean(EduTeacherTitleService.class);
			private static EduProfessionalTitleService eduProfessionalTitleService = SpringUtils.getBean(EduProfessionalTitleService.class);
			private static EduTwoOrganizationService eduTwoOrganizationService = SpringUtils.getBean(EduTwoOrganizationService.class);
			private static EduSubjectService eduSubjectService = SpringUtils.getBean(EduSubjectService.class);
			private static EduTalentService eduTalentService = SpringUtils.getBean(EduTalentService.class);
			private static EduIndustryService eduIndustryService = SpringUtils.getBean(EduIndustryService.class);
		}
		
		public static List<EduIndustry> getEduIndustry(EduIndustry eduIndustry){
			return Static.eduIndustryService.findList(eduIndustry);
		}
		
		public static List<EduIndustry> getEduIndustryAllList(){
			@SuppressWarnings("unchecked")
			List<EduIndustry> areaList = (List<EduIndustry>)CacheUtils.get(CACHE_EDU_INDUSTRY_ALL_LIST);
			if (areaList == null){
				areaList = Static.eduIndustryService.findList(new EduIndustry());
				CacheUtils.put(CACHE_EDU_INDUSTRY_ALL_LIST, areaList);
			}
			return areaList;
		}
		
		public static List<EduTalent> getEduTalents(EduTalent eduTalent){
			return Static.eduTalentService.findList(eduTalent);
		}
		
		public static List<EduTalent> getEduTalentAllList(){
			@SuppressWarnings("unchecked")
			List<EduTalent> areaList = (List<EduTalent>)CacheUtils.get(CACHE_EDU_TALENT_ALL_LIST);
			if (areaList == null){
				areaList = Static.eduTalentService.findList(new EduTalent());
				CacheUtils.put(CACHE_EDU_TALENT_ALL_LIST, areaList);
			}
			return areaList;
		}
		
		public static List<EduTwoOrganization> getEduTwoOrganizationAllList(){
			@SuppressWarnings("unchecked")
			List<EduTwoOrganization> areaList = (List<EduTwoOrganization>)CacheUtils.get(CACHE_EDU_TWO_ORGANIZATION_ALL_LIST);
			if (areaList == null){
				areaList = Static.eduTwoOrganizationService.findList(new EduTwoOrganization());
				CacheUtils.put(CACHE_EDU_TWO_ORGANIZATION_ALL_LIST, areaList);
			}
			return areaList;
		}
		
		public static List<EduSubject> getEduSubject(EduSubject eduSubject){
			return Static.eduSubjectService.findList(eduSubject);
		}
		
		public static List<EduSubject> getEduSubjectAllList(){
			@SuppressWarnings("unchecked")
			List<EduSubject> areaList = (List<EduSubject>)CacheUtils.get(CACHE_EDU_SUBJECT_ALL_LIST);
			if (areaList == null){
				areaList = Static.eduSubjectService.findList(new EduSubject());
				CacheUtils.put(CACHE_EDU_SUBJECT_ALL_LIST, areaList);
			}
			return areaList;
		}
		/**
		 * 获取所有区域列表（系统级别缓存）
		 * @return
		 */
		public static List<EduTeacherTitle> getTeacherAllList(){
			@SuppressWarnings("unchecked")
			List<EduTeacherTitle> areaList = (List<EduTeacherTitle>)CacheUtils.get(CACHE_TEACHER_ALL_LIST);
			if (areaList == null){
				areaList = Static.eduTeacherTitleService.findList(new EduTeacherTitle());
				CacheUtils.put(CACHE_TEACHER_ALL_LIST, areaList);
			}
			return areaList;
		}
		public static List<EduProfessionalTitle> getProfessionalAllList(){
			@SuppressWarnings("unchecked")
			List<EduProfessionalTitle> areaList = (List<EduProfessionalTitle>)CacheUtils.get(CACHE_PROFESSIONAL_ALL_LIST);
			if (areaList == null){
				areaList = Static.eduProfessionalTitleService.findList(new EduProfessionalTitle());
				CacheUtils.put(CACHE_TEACHER_ALL_LIST, areaList);
			}
			return areaList;
		}
		
		/**
		 * 清理区域缓存
		 */
		public static void clearCache(){
			CacheUtils.remove(CACHE_TEACHER_ALL_LIST);
			CacheUtils.remove(CACHE_PROFESSIONAL_ALL_LIST);
			CacheUtils.remove(CACHE_EDU_TWO_ORGANIZATION_ALL_LIST);
			CacheUtils.remove(CACHE_EDU_SUBJECT_ALL_LIST);
			CacheUtils.remove(CACHE_EDU_TALENT_ALL_LIST);
			CacheUtils.remove(CACHE_EDU_INDUSTRY_ALL_LIST);	
		}
}
